<?php

namespace App\Transformers;

use App\Models\User;

class UserTransformer extends BaseTransformer
{
    protected $availableIncludes = ['detail', 'wallet', 'shop'];

    public function transform(User $model)
    {
        return [
            'id' => $model->id,
            'user_nu' => $model->user_nu,         #用户编号
            'username' => $model->username,        #登录账户
            'email' => $model->email,           #邮箱
            'nick_name' => $model->nick_name,       #用户id
            'avatar' => image_url($model->avatar),          #头像
            'phone' => $model->phone,           #手机号
            'role' => $model->role,            #角色 customer:顾客,seller:商家
            'login_status' => $model->login_status,    #登录状态 forbidden, normal
            'gag_status' => $model->gag_status,      #禁言状态 forbidden, normal
            'gag_duration' => $model->gag_duration,    #禁言时长 分钟
            'created_at' => $model->created_at->toDateTimeString(),
        ];
    }

    public function includeDetail(User $model)
    {
        return $this->item($model->data, new UserDataTransformer());
    }

    public function includeWallet(User $model)
    {
        return $this->item($model->wallet, new WalletTransformer());
    }

    public function includeShop(User $model)
    {
        return $this->item($model->shop, new ShopTransformer());
    }
}
